<template>
  <!-- 订单评论审核 -->
  <div>
    <!-- 头部查询 -->
    <div class="header">
      <!-- 输入关键字查询 -->
      <el-input
        v-model="keyword"
        placeholder="请输入关键字"
        style="width: 240px"
        clearable
      />
      <!-- 输入订单编号查询 -->
      <el-input
        v-model="orderid"
        placeholder="请输入订单编号"
        style="width: 240px"
        clearable
      />
      <!-- 订单审核下拉选择框 -->
      <el-select v-model="orderstatus" clearable placeholder="请选择状态">
        <el-option label="通过" value="通过" />
        <el-option label="不通过" value="不通过" />
        <el-option label="未审核" value="未审核" />
      </el-select>
      <!-- 查询按钮 -->
      <el-button type="success" @click="choose">查询</el-button>
    </div>
    <!-- 表格数据展示 -->
    <div class="table_content">
      <el-table :data="OrderList" style="width: 100%">
        <!-- 序号 -->
        <el-table-column type="index" prop="id" label="序号" align="center" />
        <!-- 评论内容 -->
        <el-table-column prop="content" label="评论内容" align="center" />
        <!-- 顾客编号 -->
        <el-table-column prop="customerId" label="顾客编号" align="center" />
        <!-- 订单编号 -->
        <el-table-column prop="orderId" label="订单编号" align="center" />
        <!-- 评论时间 -->
        <el-table-column prop="commentTime" label="评论时间" align="center">
          <template slot-scope="scope">
            <span>{{
              moment(scope.row.commentTime).format("YYYY-MM-DD HH:mm:SS")
            }}</span>
          </template>
        </el-table-column>
        <!-- 状态 -->
        <el-table-column label="评论状态" show-overflow-tooltip align="center">
          <template slot-scope="scope">
            <el-tag
              v-if="scope.row.status == '通过'"
              size="small"
              type="success"
            >
              {{ scope.row.status }}
            </el-tag>
            <el-tag
              v-else-if="scope.row.status == '不通过'"
              size="small"
              type="danger"
            >
              {{ scope.row.status }}
            </el-tag>
            <el-tag
              v-else-if="scope.row.status == '未审核'"
              size="small"
              type="info"
            >
              {{ scope.row.status }}
            </el-tag>
          </template>
        </el-table-column>
        <!-- 操作 -->
        <!-- 操作 -->
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.status=='通过'||scope.row.status=='不通过'"
              type="text"
              size="small"
              style="color:#E6A23C"
              @click="handleClick(scope.row.id)"
            >删除</el-button>
            <span v-else>
              <el-button type="text" size="small" style="color:#E6A23C" @click="handleClick(scope.row.id)">删除</el-button>
              <el-button type="text" size="small" style="color:#67C23A" @click="checkpass(scope.row.id)">通过</el-button>
              <el-button type="text" size="small" style="color:#F56C6C" @click="checknopass(scope.row.id)">不通过</el-button>
            </span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 底部分页查询 -->
    <div class="footer">
      <el-pagination
        :current-page="currentPage"
        :page-sizes="[2, 4, 6, 8]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script>
import { get, post } from '@/utils/request'
const moment = require('moment')
export default {
  data() {
    return {
      // 关键字
      keyword: '',
      // 订单编号
      orderid: '',
      // 订单审核状态
      orderstatus: '',
      // 订单信息全部信息
      OrderList: [],
      // 页面展示数据的总条数
      total: 10,
      // 当前页码
      currentPage: 1,
      // 每页要展示的数据
      pageSize: 8,
      // 发送查询订单信息数组
      queryorder: []
    }
  },
  computed: {},

  created() {
    this.getAllorder()
  },
  mounted() {},
  methods: {
    // 时间戳装换方法
    moment,
    // 发送网络请求拿到全部订单信息
    async getAllorder() {
      const data = {
        page: this.currentPage,
        pageSize: this.pageSize
      }
      const res = await get('/orderComment/pageQuery', {
        ...data,
        ...this.queryorder
      })
      // console.log(res);
      this.OrderList = res.data.list
      this.total = res.data.total
    },

    // 头部查询按钮方法
    choose() {
      const data = {
        // 根据关键字查询内容
        content: this.keyword,
        // 根据审核状态查询
        status: this.orderstatus,
        // 根据订单编号查询
        orderId: this.orderid
      }
      // 格式化参数 当某个属性没有值的时候将其删除 以防影响网络请求的操作
      for (const key in data) {
        if (!data[key]) {
          delete data[key]
        }
      }
      (this.queryorder = data), (this.currentPage = 1)
      this.getAllorder()
    },
    // 每页展示的数据条数
    handleSizeChange(val) {
      this.pageSize = val
      this.currentPage = 1
      this.getAllorder()

      //   console.log(`每页 ${val} 条`);
    },

    // 控制当前页的页数
    handleCurrentChange(val) {
      this.currentPage = val
      this.getAllorder()
      // console.log(`当前页: ${val}`);
    },

    // 根据id删除订单评论
    async handleClick(id) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        const res = await get('/orderComment/deleteById', { id })
        if (res.status == 200) {
          this.$message({
            type: 'success',
            message: res.message
          })
          // 刷新页面
          this.getAllorder()
        } else {
          this.$message({
            type: 'danger',
            message: res.message
          })
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },

    // 根据id给订单评论审核通过
    async checkpass(id) {
      const res = await post('/orderComment/checkPass', { id })
      if (res.status == 200) {
        this.$message({
          message: res.message,
          type: 'success'
        })
      } else {
        this.$message({
          message: res.message,
          type: 'danger'
        })
      }
      // 刷新页面
      this.getAllorder()
    },

    // 根据id给订单评论审核不通过
    async checknopass(id) {
      const res = await post('/orderComment/checkNoPass', { id })
      if (res.status == 200) {
        this.$message({
          message: res.message,
          type: 'success'
        })
      } else {
        this.$message({
          message: res.message,
          type: 'danger'
        })
      }
      // 刷新页面
      this.getAllorder()
    }

  }
}
</script>
<style scoped>
/* 分页区域的样式 */
.footer {
  position: fixed;
  bottom: 40px;
  right: 10px;
}
</style>
